home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 3 / CD ACTUAL 3.iso / linux / system / bsvc-1.000 / bsvc-1 / bsvc-1.0.4 / src / Tools / xtermpipe / xtermpipe.cxx < prev   
Encoding:
C/C++ Source or Header  |  1995-07-26  |  1.3 KB  |  71 lines

  1. ///////////////////////////////////////////////////////////////////////////////
  2. // This simple program can be used with the Motorola M68681 DUART
  3. // to pipe input and output to an xterm.
  4. //
  5. // By: Bradford W. Mott
  6. ///////////////////////////////////////////////////////////////////////////////
  7.  
  8. #include <sys/time.h>
  9. #include <sys/types.h>
  10. #include <sys/param.h>
  11. #include <unistd.h>
  12. #include <stdlib.h>
  13. #include <string.h>
  14. #include <stdio.h>
  15. #include <signal.h>
  16.  
  17. int WaitForIO(int pipe_id)
  18. {
  19.   fd_set readfds;
  20.   fd_set writefds;
  21.   fd_set exceptfds;
  22.  
  23.   FD_ZERO(&readfds);
  24.   FD_ZERO(&writefds);
  25.   FD_ZERO(&exceptfds);
  26.  
  27.   FD_SET(0, &readfds);
  28.   FD_SET(pipe_id, &readfds);
  29.  
  30. # ifdef _HPUX_SOURCE
  31.     select(pipe_id + 1, (int*)&readfds, (int*)&writefds, (int*)&exceptfds,
  32.            (void*)0);
  33. # else
  34.     select(pipe_id + 1, &readfds, &writefds, &exceptfds, (void*)0);
  35. # endif
  36.  
  37.   if(FD_ISSET(0, &readfds))
  38.     return(0);
  39.   else
  40.     return(1);
  41. }
  42.  
  43. main(int argc,char **argv)
  44. {
  45.   int read_id, write_id;
  46.  
  47.   system("stty -echo -echoe -echonl raw");
  48.  
  49.   read_id=3;
  50.   write_id=4;
  51.  
  52.   while(1)
  53.   {
  54.     if(WaitForIO(read_id))
  55.     {
  56.       char c;
  57.  
  58.       read(read_id, &c, 1);
  59.       write(1,&c,1);
  60.     }
  61.     else
  62.     {
  63.       char c;
  64.  
  65.       read(0, &c, 1);
  66.       if(write(write_id, &c, 1)<0)
  67.         printf("Error on write!!!\n");
  68.     }
  69.   }
  70. }
  71.